package com.horse.cloud.framework.general.enums;


/**
 * @create :Created by intelliJ IDEA 16.1.1 .
 * @author :bing.Pan 15923508369@163.com .
 * @gmdate :2017/1/18 11:02
 * @sidesc :统一返回状态码 10000 - 19999 消息提示
 *                       20000 - 29999 正常返回
 *                       30000 - 39999
 *                       40000 - 40000 客户端错误
 *                       50000 - 59999 服务端错误
 */
public enum ResponseCodeEnums implements ResponseCodeInterface {

    SUCCESS                                 (20000, 20000, "success", "执行成功"),

    CONFIG_DATABASE_MASTER_CODE             (30000, 30001, "主数据源配置异常",""),
    CONFIG_DATABASE_SLAVE_CODE              (30000, 30002, "从数据源配置异常",""),

    //客户端请求异常
    CLIENT_PARAM_PARSE_ERROR                (40000, 40001, "参数解析失败/参数缺少", ""),
    CLIENT_PARAM_MISS                       (40000, 40002, "参数丢失", ""),
    CLIENT_PARAM_ERROR                      (40000, 40003, "参数错误", ""),
    CLIENT_UNABLE_RESOLVE_ERR               (40000, 40004, "坏请求", ""),
    CLIENT_NO_SUPPORT_METHOD                (40000, 40005, "不支持该请求方法", ""),
    CLIENT_NO_SUPPORT_TYPE                  (40000, 40006, "不支持当前媒体类型", ""),


    //服务端处理异常

    SERVER_GATEWAY_FILTER_ERROR             (51000, 51001, "服务网关过滤器执行异常",""),
    SERVER_UNKNOWN_ERROR                    (52000, 52001, "服务器端异常", ""),
    SERVER_LOGIC_PARAM_MISS                 (52000, 52002, "必要逻辑参数为空", ""),


    SERVER_CHECK_NO_DATE                    (59000, 59001, "转换类型失败",""),
    SERVER_CHECK_NO_ENUM                    (59000, 59002, "转换enum类型失败",""),
    SERVER_CHECK_NO_ANNOTATION              (59000, 59003, "未启用对应注解",""),




    // 登陆
    LOGIN_USER_MISS                         (60000, 60001, "用户不存在",""),
    LOGIN_USER_NOT_AVAILABLE                (60000, 60002, "账户已被禁用",""),
    LOGIN_PASSWORD_ERR                      (60000, 60003, "密码不正确",""),
    LOGIN_TOME_OUT                          (60000, 60004, "登陆过期",""),
    LOGIN_NOT_LOGIN                         (60000, 60005, "用户未登陆",""),


    //安全校验
    SECURITY_NO_SIGNATURE                   (70000, 70001, "无效签名方法",""),
    SECURITY_NO_TOKEN                       (70000, 70002, "token不能为空",""),




    //数据库相关
    DATA_TRANSACTION_ROLL_BACK              (80000, 80001, "dataaccess transaction RollbackOnly",""),
    DATA_NO_MASTER_DATABASES                (80000, 80002, "未找到数据库配置信息",""),


    //微服务间调用异常
    MINOR_SERVER_HYSTRIX_FALLBACK           (90000, 90001, "hystrix-fallback",""),
    MINOR_SERVER_NO_USE                     (90000, 90002,"微服务不可用",""),

    ;

    private int code;
    private int subCode;

    private String description;

    private String detailMessage;


    public int getCode() {
        return code;
    }

    public int getSubCode() {
        return subCode;
    }

    public String getDescription() {
        return description;
    }

    public String getDesc(int code) {

        for (ResponseCodeEnums responseCodeEnums : ResponseCodeEnums.values()) {
            if(responseCodeEnums.getCode() == code){
                return responseCodeEnums.getDescription();
            }
            
        }

        return "";
    }



    public String getDetailMessage() {
        return detailMessage;
    }

    ResponseCodeEnums(int code, int subCode, String description, String detailMessage) {
        this.code = code;
        this.subCode = subCode;
        this.description = description;
        this.detailMessage = detailMessage;
    }
}
